//
//  LoginViewController.m
//  fastwatch
//
//  Created by lanou3g on 15/10/31.
//  Copyright © 2015年 songhaowen. All rights reserved.
//

#import "LoginViewController.h"
#import "RegistViewController.h"
#import "UserController.h"
#import <BmobSDK/Bmob.h>

@interface LoginViewController ()
@property (weak, nonatomic) IBOutlet UIButton *LoginBtn;
@property (weak, nonatomic) IBOutlet UIButton *RegistBtn;

@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
     self.navigationController.navigationBar.barTintColor = [UIColor orangeColor];
    //设置title
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 40)];
    [titleLabel setText:@"用户登录"];
    [titleLabel setTextAlignment:NSTextAlignmentCenter];
    [titleLabel setTextColor:[UIColor blackColor]];
    [titleLabel setFont:[UIFont boldSystemFontOfSize:19]];
    [titleLabel setBackgroundColor:[UIColor clearColor]];
    self.navigationItem.titleView = titleLabel;
    
    UIBarButtonItem * backButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(backUserBtn)];
    self.navigationItem.leftBarButtonItem = backButtonItem;
    self.LoginBtn.layer.cornerRadius = 10;
    self.RegistBtn.layer.cornerRadius = 10;
    
//    self.accountTextField.keyboardType = UIKeyboardTypeDefault;
//    self.passwTextField.keyboardType = UIKeyboardTypeDefault;
//    self.accountTextField.returnKeyType=UIReturnKeyGo;
//    self.passwTextField.returnKeyType=UIReturnKeyGo;

    


}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    
        [self.view endEditing:YES];    
    
}




- (void)backUserBtn {
   [self dismissViewControllerAnimated:YES completion:nil];
    
}


- (IBAction)jumpRegistBtn:(id)sender {
    
    RegistViewController *registVC = [[RegistViewController alloc] init];
    UINavigationController *registNC = [[UINavigationController alloc] initWithRootViewController:registVC];
 
    
    [self presentViewController:registNC animated:YES completion:nil];
        
}
- (IBAction)LoginBtn:(id)sender {
    NSString *account =  self.accountTextField.text;
    NSString *psww  = self.passwTextField.text;
  [BmobUser loginInbackgroundWithAccount:account andPassword:psww block:^(BmobUser *user, NSError *error) {
      if (error == nil) {
          UserController *user = [[UserController alloc]init];
    
          
          [self presentViewController:user animated:YES completion:nil];
              user.logoutBtn.hidden = NO;
              user.firstView.hidden = NO;
              user.loginButton.hidden = YES;
              user.firstLabel.hidden = YES;
           user.logoutBtn.layer.cornerRadius = 10;
          
         // BmobUser *bUser = [BmobUser getCurrentObject];
          user.nickTextField.text =  account;
          
          
      }else{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"用户名或密码错误" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
          [self.view addSubview:alertView];
          [alertView show];
          
      }
      
  }];
    
 
    
    
}





@end
